%% Script for blanking OD600 values from 96-well plates, data from Epoch 2 plate reader.
% Ben Knapp, July 3rd, 2019

% This script requires two different .txt files from Epoch2 plate readers.
% It will perform an input function twice to modify the 'plate' data
% structure.

%% Import plates
% Import blank function first
blankplate = import_plate_96well_gui(25);
% Import plate with samples
sampleplate = import_plate_96well_gui(25);

%% Now perform blanking operation, along with growth rate

for k=1:length(sampleplate)
    
    % Blank the OD600 values
    blk = blankplate(k).OD600(end);
    od = sampleplate(k).OD600;
    odblk = od-blk;
    
    sampleplate(k).OD600_blanked = odblk;
    sampleplate(k).blank_value = blk;
    
    % Calculate growth rate 
    smf = 8; % Smoothing factor for growth rate calculation
    t = sampleplate(k).time;
    dt = mean(diff(t)); % Obtain time interval
    logodblk = log(odblk);
    grblk = gradient(smooth(logodblk,smf))/dt;
    
    % Correct for complex values in growth rate
    grblk(imag(grblk)~=0) = nan;
    
    sampleplate(k).growth_rate_blanked = grblk;
    sampleplate(k).growth_rate_sliding = AAD_growthrate_sliding(t,logodblk,8);
    
    
    
end